<?php 




$client = new swoole_client(SWOOLE_TCP | SWOOLE_ASYNC); //异步非阻塞

$client->on("connect", function($cli) {
    $cli->send("hello world\n");
});

$client->on("receive", function($cli, $data) {
        echo "received: $data\n";
        sleep(1);

        $str = fgets(STDIN);
        $cli->send($str);
});

$client->on("close", function($cli){
    echo "closed\n";
});

$client->on("error", function($cli){
    exit("error\n");
});

$client->connect('0.0.0.0', 80, 0.5);


?>